package nku.csc360;

import java.util.Date;

public class Checking extends Account{
	
	private int overdraft = 1000; // Acutal overdraft available to customer for his account if account is in good stading

	//Having a default constructor just in case
    public Checking() {
    	
    	//Calling super constructor for null argument this doesn't need to be called it is done
    	//Automatically
    	super();
    }
    
    //Constructor if there is a default of 1000 dollar over draft protection
 	public Checking(int id, double balance, double annualInterestRate, Date dateCreated){
    	
    	//Calling super constructor to set default values
    	super(id, balance, annualInterestRate, dateCreated);
    			
    }
    
    //Constructor if there is a different value for the over draft protection
    public Checking(int id, double balance, double annualInterestRate, Date dateCreated, int overdraft){
    	
    	//Calls super constructor to set default values
    	super(id, balance, annualInterestRate, dateCreated);
    	
    	//Initilizing overdraft protection values
    	this.overdraft = overdraft;
    	}    

	//Implenting the mehtod of withdrawing using overdraft protection
  	public void withdraw(double amount) {
  		
  		//Checking if the amount of withdrwal will put the balance above the overdraft protection
  		//If it does i print a witdrwal error message and do not contineu with the transaction
   		if ((getBalance() - amount) < -overdraft){
   			System.out.println("-> Withdraw operation cannot be completed: overdraft limit exceeded.");
   			return;
   		}
   		
   		//If patron has enough money to cover his withdrawal nothing is done except his balance update.
   		else 
   			setBalance(getBalance() - amount);
   			
   		System.out.println("Withdrawal : " + amount + " from checking account " + getId() + ", Balance: " + getBalance());
  	}
  	
  	// Here is an overriding mehtod for the deposit method
  	public void deposit(double amount) {
  		
  		//First i deposit money into the account
  		setBalance(getBalance() + amount);
   		System.out.println("Deposit : " + amount + " from checking account " + getId() + ", Balance: " + getBalance());
  				
  	}
  	
  	//What to display when printing a checking account
  	public String toString() {
    	return "Account " + getId() + " (created " + getDateCreated() + ") has balance " + getBalance() +" and overdraft limit " + overdraft;
  	}
}